package com.langll.ai.neo4j;

import com.langll.ai.AIChatApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.neo4j.driver.*;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.test.context.junit4.SpringRunner;

import static org.neo4j.driver.Values.parameters;
/**
 * neo4j 图数据库测试
 */
@SpringBootTest(classes = AIChatApplication.class)
@RunWith(SpringRunner.class)
public class TestConnection {

    @Test
    public void TestExample() throws Exception {
        Driver driver = GraphDatabase.driver("bolt://localhost:7687",
                AuthTokens.basic("neo4j", "neo4j_password"));
        Session session = driver.session();

        final String message = "Greeting";
        String greeting = session.writeTransaction(
                new TransactionWork<String>(){
                    public String execute(Transaction tx ) {
                        Result result = tx.run("CREATE (a:Greeting) " +
                                        "SET a.message = $message " +
                                        "RETURN a.message + ', from node ' + id(a)",
                                parameters( "message", message));
                        return result.single().get( 0 ).asString();
                    }
                }
        );

        System.out.println(greeting);

        System.out.println("OK");
        driver.close();
    }

    @Test
    public void addPerson() throws Exception {
    }
}
